/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package org.achartengine;

import android.content.Context;
import android.graphics.*;
import android.os.Build;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;

import org.achartengine.ITouchHandler;
import org.achartengine.TouchHandler;
import org.achartengine.TouchHandlerOld;
import org.achartengine.chart.AbstractChart;
import org.achartengine.chart.RoundChart;
import org.achartengine.chart.XYChart;
import org.achartengine.model.Point;
import org.achartengine.model.SeriesSelection;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.tools.FitZoom;
import org.achartengine.tools.PanListener;
import org.achartengine.tools.Zoom;
import org.achartengine.tools.ZoomListener;

// Referenced classes of package org.achartengine:
//            TouchHandlerOld, TouchHandler, ITouchHandler

public class GraphicalView extends View {

	public GraphicalView(Context context, AbstractChart abstractchart) {
		super(context);
		mRect = new Rect();
		mZoomR = new RectF();
		zoomSize = 50;
		mPaint = new Paint();
		mChart = abstractchart;
		mHandler = new Handler();
		if (mChart instanceof XYChart)
			mRenderer = ((XYChart) mChart).getRenderer();
		else
			mRenderer = ((RoundChart) mChart).getRenderer();
		if (mRenderer.isZoomButtonsVisible()) {
			zoomInImage = BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom_in.png"));
			zoomOutImage = BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom_out.png"));
			fitZoomImage = BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom-1.png"));
		}
		if ((mRenderer instanceof XYMultipleSeriesRenderer)
				&& ((XYMultipleSeriesRenderer) mRenderer).getMarginsColor() == 0)
			((XYMultipleSeriesRenderer) mRenderer).setMarginsColor(mPaint
					.getColor());
		if (mRenderer.isZoomEnabled() && mRenderer.isZoomButtonsVisible()
				|| mRenderer.isExternalZoomEnabled()) {
			mZoomIn = new Zoom(mChart, true, mRenderer.getZoomRate());
			mZoomOut = new Zoom(mChart, false, mRenderer.getZoomRate());
			mFitZoom = new FitZoom(mChart);
		}
		int i = 7;
		try {
			i = Integer.valueOf(android.os.Build.VERSION.SDK).intValue();
		} catch (Exception exception) {
		}
		if (i < 7)
			mTouchHandler = new TouchHandlerOld(this, mChart);
		else
			mTouchHandler = new TouchHandler(this, mChart);
	}

	public SeriesSelection getCurrentSeriesAndPoint() {
		return mChart
				.getSeriesAndPointForScreenCoordinate(new Point(oldX, oldY));
	}

	public double[] toRealPoint(int i) {
		if (mChart instanceof XYChart) {
			XYChart xychart = (XYChart) mChart;
			return xychart.toRealPoint(oldX, oldY, i);
		} else {
			return null;
		}
	}

	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.getClipBounds(mRect);
		int i = mRect.top;
		int j = mRect.left;
		int k = mRect.width();
		int l = mRect.height();
		if (mRenderer.isInScroll()) {
			i = 0;
			j = 0;
			k = getMeasuredWidth();
			l = getMeasuredHeight();
		}
		mChart.draw(canvas, j, i, k, l, mPaint);
		if (mRenderer != null && mRenderer.isZoomEnabled()
				&& mRenderer.isZoomButtonsVisible()) {
			mPaint.setColor(ZOOM_BUTTONS_COLOR);
			zoomSize = Math.max(zoomSize, Math.min(k, l) / 7);
			mZoomR.set((j + k) - zoomSize * 3, (float) (i + l)
					- (float) zoomSize * 0.775F, j + k, i + l);
			canvas.drawRoundRect(mZoomR, zoomSize / 3, zoomSize / 3, mPaint);
			float f = (float) (i + l) - (float) zoomSize * 0.625F;
			canvas.drawBitmap(zoomInImage, (float) (j + k) - (float) zoomSize
					* 2.75F, f, null);
			canvas.drawBitmap(zoomOutImage, (float) (j + k) - (float) zoomSize
					* 1.75F, f, null);
			canvas.drawBitmap(fitZoomImage, (float) (j + k) - (float) zoomSize
					* 0.75F, f, null);
		}
	}

	public void setZoomRate(float f) {
		if (mZoomIn != null && mZoomOut != null) {
			mZoomIn.setZoomRate(f);
			mZoomOut.setZoomRate(f);
		}
	}

	public void zoomIn() {
		if (mZoomIn != null) {
			mZoomIn.apply();
			repaint();
		}
	}

	public void zoomOut() {
		if (mZoomOut != null) {
			mZoomOut.apply();
			repaint();
		}
	}

	public void zoomReset() {
		if (mFitZoom != null) {
			mFitZoom.apply();
			mZoomIn.notifyZoomResetListeners();
			repaint();
		}
	}

	public void addZoomListener(ZoomListener zoomlistener, boolean flag,
			boolean flag1) {
		if (flag) {
			if (mZoomIn != null) {
				mZoomIn.addZoomListener(zoomlistener);
				mZoomOut.addZoomListener(zoomlistener);
			}
			if (flag1)
				mTouchHandler.addZoomListener(zoomlistener);
		}
	}

	public synchronized void removeZoomListener(ZoomListener zoomlistener) {
		if (mZoomIn != null) {
			mZoomIn.removeZoomListener(zoomlistener);
			mZoomOut.removeZoomListener(zoomlistener);
		}
		mTouchHandler.removeZoomListener(zoomlistener);
	}

	public void addPanListener(PanListener panlistener) {
		mTouchHandler.addPanListener(panlistener);
	}

	public void removePanListener(PanListener panlistener) {
		mTouchHandler.removePanListener(panlistener);
	}

	protected RectF getZoomRectangle() {
		return mZoomR;
	}

	public boolean onTouchEvent(MotionEvent motionevent) {
		if (motionevent.getAction() == 0) {
			oldX = motionevent.getX();
			oldY = motionevent.getY();
		}
		if (mRenderer != null
				&& (mRenderer.isPanEnabled() || mRenderer.isZoomEnabled())
				&& mTouchHandler.handleTouch(motionevent))
			return true;
		else
			return super.onTouchEvent(motionevent);
	}

	public void repaint() {
		mHandler.post(new Runnable() {

			public void run() {
				invalidate();
			}

			final GraphicalView this$0;

			{
				this$0 = GraphicalView.this;
				//super();
			}
		});
	}

	public void repaint(final int left, final int top, final int right,
			final int bottom) {
		mHandler.post(new Runnable() {

			public void run() {
				invalidate(left, top, right, bottom);
			}

			/*final int val$left;
			final int val$top;
			final int val$right;
			final int val$bottom;
			final GraphicalView this$0;

			{
				this$0 = GraphicalView.this;
				val$left = left;
				val$top = top;
				val$right = top;
				val$bottom = bottom;
				super();
			}*/
		});
	}

	public Bitmap toBitmap() {
		setDrawingCacheEnabled(false);
		if (!isDrawingCacheEnabled())
			setDrawingCacheEnabled(true);
		if (mRenderer.isApplyBackgroundColor())
			setDrawingCacheBackgroundColor(mRenderer.getBackgroundColor());
		setDrawingCacheQuality(1048576);
		return getDrawingCache(true);
	}

	private AbstractChart mChart;
	private DefaultRenderer mRenderer;
	private Rect mRect;
	private Handler mHandler;
	private RectF mZoomR;
	private Bitmap zoomInImage;
	private Bitmap zoomOutImage;
	private Bitmap fitZoomImage;
	private int zoomSize;
	private static final int ZOOM_BUTTONS_COLOR = Color
			.argb(175, 150, 150, 150);
	private Zoom mZoomIn;
	private Zoom mZoomOut;
	private FitZoom mFitZoom;
	private Paint mPaint;
	private ITouchHandler mTouchHandler;
	private float oldX;
	private float oldY;

}


/*
	DECOMPILATION REPORT

	Decompiled from: D:\Code\CCBHelper\jar\achartengine-0.7.0.jar
	Total time: 31 ms
	Jad reported messages/errors:
	Exit status: 0
	Caught exceptions:
*/